/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Evento;

import Controlador.ControladorColaborador;
import Controlador.ControladorEvento;
import Controlador.ControladorUsuario;
import Logica.Colaborador;
import Logica.Evento;
import Logica.Usuario;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author User
 */
public class PanelColaborador extends javax.swing.JPanel {
   ControladorUsuario cuser; 
   ControladorColaborador ccol;
   Evento e;
   List<Colaborador> colaboradores;
    /**
     * Creates new form PanelColaborador
     */
    public PanelColaborador(Evento e) {
        this.e=e;
        cuser=new ControladorUsuario();
        ccol= new ControladorColaborador();
        initComponents();
        cargarColaboradores();
    }
    
    public void limpiarDatos(){
        cdir.setText("");
        cemail.setText("");
        cid.setText("");
        cnombre.setText("");
        clogin.setText("");
        cpass.setText("");
        cpass2.setText("");
        ctel.setText("");
    }
    
    public void cargarColaboradores(){
        colaboradores = ccol.listar();
        boxColaboradores.removeAllItems();
        for(int i=0;i<colaboradores.size();i++){
            if(colaboradores.get(i).getIdEvento().equals(e)){
                boxColaboradores.addItem(colaboradores.get(i).getNombre()+"-"+colaboradores.get(i).getCargo());
            }else;
        }
    }
    
    public void actualizarColaboradores(){
        colaboradores = ccol.listar();
        boxColaboradores.removeAllItems();
        for(int i=0;i<colaboradores.size();i++){
            if(colaboradores.get(i).getIdEvento().equals(e)){
                boxColaboradores.addItem(colaboradores.get(i).getNombre()+"-"+colaboradores.get(i).getCargo());
            }else;
        }
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        cnombre = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cid = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        ctel = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cdir = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        clogin = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        cpass = new javax.swing.JPasswordField();
        jLabel12 = new javax.swing.JLabel();
        cpass2 = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        cemail = new javax.swing.JTextField();
        botonAgregar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        boxRol = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        boxColaboradores = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cnombre1 = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        ctel1 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        cdir1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cemail1 = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        cpass1 = new javax.swing.JPasswordField();
        jLabel19 = new javax.swing.JLabel();
        cpass3 = new javax.swing.JPasswordField();
        botonConsultar = new javax.swing.JButton();
        botonEliminar = new javax.swing.JButton();
        botonEditar = new javax.swing.JButton();

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Colaborador", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 51, 255)));

        jLabel6.setText("Nombre");

        jLabel7.setText("Identificacion");

        jLabel8.setText("Teléfono");

        jLabel9.setText("Dirección");

        jLabel10.setText("Login");

        jLabel11.setText("Contraseña");

        jLabel12.setText("Confi. Contr.");

        jLabel2.setText("Email");

        botonAgregar.setText("Agregar");
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });

        jLabel1.setText("Rol");

        boxRol.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrativo", "Deportivo", "Logística" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(45, 45, 45)
                        .addComponent(cnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addComponent(cpass2, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                            .addComponent(cpass, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel7)
                                .addComponent(jLabel8)
                                .addComponent(jLabel9)
                                .addComponent(jLabel10)
                                .addComponent(jLabel2)
                                .addComponent(jLabel1))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(ctel)
                                .addComponent(cdir)
                                .addComponent(clogin)
                                .addComponent(cid)
                                .addComponent(cemail)
                                .addComponent(boxRol, 0, 164, Short.MAX_VALUE))))
                    .addComponent(botonAgregar))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(cdir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(boxRol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(clogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(cpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(cpass2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(botonAgregar)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(314, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Agregar Colaborador", jPanel1);

        jLabel3.setText("Nombre-Cargo");

        jLabel13.setText("Nombre");

        jLabel15.setText("Teléfono");

        jLabel16.setText("Dirección");

        jLabel4.setText("Email");

        jLabel18.setText("Contraseña");

        jLabel19.setText("Confi. Contr.");

        botonConsultar.setText("Consultar");
        botonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonConsultarActionPerformed(evt);
            }
        });

        botonEliminar.setText("Eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        botonEditar.setText("Editar");
        botonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(boxColaboradores, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addGap(45, 45, 45)
                        .addComponent(cnombre1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addGap(18, 18, 18)
                        .addComponent(cpass3, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel18)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cpass1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel15)
                                .addComponent(jLabel16)
                                .addComponent(jLabel4))
                            .addGap(39, 39, 39)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(ctel1)
                                .addComponent(cdir1)
                                .addComponent(cemail1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(66, 66, 66)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botonEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botonConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addComponent(botonEditar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(144, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(boxColaboradores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(cnombre1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botonEliminar)))
                    .addComponent(botonEditar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonConsultar)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(ctel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16)
                            .addComponent(cdir1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(cemail1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(cpass1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(cpass3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(160, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Editar Colaborador", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarActionPerformed
        // TODO add your handling code here:
        Colaborador col = new Colaborador();
        Usuario us = new Usuario();
        String nombre =cnombre.getText();
        String id = cid.getText();
        String login = clogin.getText();
        String pass="";
        String rol=boxRol.getSelectedItem().toString();
        String direccion = cdir.getText();
        String email = cemail.getText();
        String telefono =ctel.getText();
        col.setCargo(rol);
        col.setNombre(nombre);
        col.setDireccion(direccion);
        col.setEmail(email);
        col.setLogin(us);
        col.setTelefono(telefono);
        
        us.setLogin(login);
        us.setPass(pass);
        us.setRol(rol);
        if(cpass.getText().equals(cpass2.getText()) || cpass.getText().equals("") || cpass2.getText().equals("")){
            pass=cpass.getText();
            try{
                ccol.crearColaborador(id, nombre, rol, telefono, direccion, email, login, e.getIdEvento());
                cuser.crearUsuario(login, pass, rol);
                JOptionPane.showMessageDialog(this, "Colaborador registrado con éxito");
                actualizarColaboradores();
            }catch(Exception e){
                JOptionPane.showMessageDialog(this, "Ha ocurrido un erro al crear el colaborador","Error", JOptionPane.ERROR_MESSAGE);
            }
        }else{
             JOptionPane.showMessageDialog(this, "Las contraseñas no coinciden o los campos están vacíos");
        }
    }//GEN-LAST:event_botonAgregarActionPerformed

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed
        // TODO add your handling code here:
        int indice = boxColaboradores.getSelectedIndex();
        String idColaborador = colaboradores.get(indice).getIdColaborador();
        String log= colaboradores.get(indice).getLogin().getLogin();
        try{
            ccol.eliminar(idColaborador);
            cuser.eliminarUsuario(log);
            JOptionPane.showMessageDialog(this, "Colaborador eliminado con éxito");
            actualizarColaboradores();
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, "Ocurrio un error, intentelo de nuevo", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_botonEliminarActionPerformed

    private void botonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEditarActionPerformed
        // TODO add your handling code here:
        Colaborador col = new Colaborador();
        
        Usuario us = new Usuario();
        String nombre =cnombre1.getText();
        String idColaborador = colaboradores.get(boxColaboradores.getSelectedIndex()).getIdColaborador();
        String login = colaboradores.get(boxColaboradores.getSelectedIndex()).getLogin().getLogin();
        String pass="";
        String rol=colaboradores.get(boxColaboradores.getSelectedIndex()).getCargo();
        String direccion = cdir1.getText();
        String email = cemail1.getText();
        String telefono =ctel1.getText();
        //col.setCargo(rol);
        col.setNombre(nombre);
        col.setDireccion(direccion);
        col.setEmail(email);
        col.setLogin(us);
        col.setTelefono(telefono);
        
       // us.setLogin(login);
        us.setPass(pass);
        us.setRol(rol);
        if(cpass1.getText().equals(cpass3.getText()) || cpass1.getText().equals("") || cpass3.getText().equals("")){
            pass=cpass.getText();
            try{
                ccol.modificar(idColaborador, nombre, rol, telefono, direccion, email, login, e.getIdEvento());
                cuser.actualizarUsuario(login, pass, rol);
                JOptionPane.showMessageDialog(this, "Colaborador registrado con éxito");
                actualizarColaboradores();
            }catch(Exception e){
                JOptionPane.showMessageDialog(this, "Ha ocurrido un erro al crear el colaborador","Error", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(this, "Las contraseñas no coinciden o los campos están vacíos");
        }
        
    }//GEN-LAST:event_botonEditarActionPerformed

    private void botonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonConsultarActionPerformed
        // TODO add your handling code here:
        int indice = boxColaboradores.getSelectedIndex();
        String idColaborador = colaboradores.get(indice).getIdColaborador();
        Colaborador colab = ccol.consultar(idColaborador);
        cnombre1.setText(colab.getNombre());
        cdir1.setText(colab.getDireccion());
        cemail1.setText(colab.getEmail());
        ctel1.setText(colab.getTelefono());
    }//GEN-LAST:event_botonConsultarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAgregar;
    private javax.swing.JButton botonConsultar;
    private javax.swing.JButton botonEditar;
    private javax.swing.JButton botonEliminar;
    private javax.swing.JComboBox boxColaboradores;
    private javax.swing.JComboBox boxRol;
    private javax.swing.JTextField cdir;
    private javax.swing.JTextField cdir1;
    private javax.swing.JTextField cemail;
    private javax.swing.JTextField cemail1;
    private javax.swing.JTextField cid;
    private javax.swing.JTextField clogin;
    private javax.swing.JTextField cnombre;
    private javax.swing.JTextField cnombre1;
    private javax.swing.JPasswordField cpass;
    private javax.swing.JPasswordField cpass1;
    private javax.swing.JPasswordField cpass2;
    private javax.swing.JPasswordField cpass3;
    private javax.swing.JTextField ctel;
    private javax.swing.JTextField ctel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
